<?php

namespace Home\Model;

use Common\Model\BaseModel;

/**
 * 微信图文回复
 */

/**
 * @param  [type] $postobj array,包含微信传递过来的基本信息
 * @param  [type] $content string,返回的内容
 * @return 返回一个消息文本
 */
public function response_text($postobj,$content){
	$toUser   = $postobj->FromUserName;
	$fromUser = $postobj->ToUserName;
	$time     = time();
	$msgtype  = 'text';
	$template = "<xml>
                 <ToUserName><![CDATA[%s]]></ToUserName>
                 <FromUserName><![CDATA[%s]]></FromUserName>
                 <CreateTime>%s</CreateTime>
                 <MsgType><![CDATA[%s]]></MsgType>
                 <Content><![CDATA[%s]]></Content>
                 </xml>";
    $info = sprintf($template,$toUser,$fromUser,$time,$Msgtype,$conent);
    return $info;
}
public function response_img_text($postobj){

	   $article =array(
	   			'title'=>'这是个测试',
	   			'description'=>'this is for test',
	   			'picUrl' =>'http://pic6.nipic.com/20091207/3337900_161732052452_2.jpg',
	   			'url' =>'https://www.baidu.com/',
	   			);
	   $toUser = $postobj->FromUserName;
	   $fromUser = $postobj->ToUserName;
	   $time   =time();
	   $msgType = 'news';
	   $template  ="<xml>
			<ToUserName><![CDATA[%s]]></ToUserName>
			<FromUserName><![CDATA[%s]]></FromUserName>
			<CreateTime>%s</CreateTime>
			<MsgType><![CDATA[%s]]></MsgType>
			<ArticleCount>1</ArticleCount>
			<Articles>";
	   $template .="<item>//如果添加多图文的话，这里加foreach循环即可
			<Title><![CDATA[".$article['title']."]]></Title> 
			<Description><![CDATA[".$article['description']."]]></Description>
			<PicUrl><![CDATA[".$article['picUrl']."]]></PicUrl>
			<Url><![CDATA[".$article['url']."]]></Url>
			</item>";
	   $template .="<item>
			<Title><![CDATA[title]]></Title>
			<Description><![CDATA[description]]></Description>
			<PicUrl><![CDATA[picurl]]></PicUrl>
			<Url><![CDATA[url]]></Url>
			</item>
			</Articles>
			</xml>";
	   $info  = sprintf($template,$toUser,$fromUser,$time,$msgType);
	   return $info;
	}